package com.worldcup.model.dto;


import com.worldcup.model.Country;
import com.worldcup.model.PredictGroup;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author duwan.zq
 * @date 2018/05/26
 */
@Getter
@Setter
public class PredictGroupDTO implements Serializable{

    private String openid;

    private String group;

    @NotNull
    private Integer rank;

    @NotNull
    private Integer countryId;

    private String countryName;

    private String countryImgUrl;

    public PredictGroupDTO(){
    }

    public PredictGroupDTO(PredictGroup predictGroup, Country country) {
        if(predictGroup != null){
            this.openid = predictGroup.getOpenid();
            this.group = predictGroup.getGroupName();
            this.rank = predictGroup.getRank();
            this.countryId = predictGroup.getCountryId();
        }
        if(country != null){
            this.countryName = country.getName();
            this.countryImgUrl = country.getImgUrl();
        }
    }

    public PredictGroup toPredictGroup() {
        PredictGroup predictGroup = new PredictGroup();
        predictGroup.setOpenid(this.openid);
        predictGroup.setGroupName(this.group);
        predictGroup.setRank(this.rank);
        predictGroup.setCountryId(this.countryId);
        return predictGroup;
    }

    public PredictGroup toPredictGroup(String openid, String group) {
        PredictGroup result = toPredictGroup();
        result.setOpenid(openid);
        result.setGroupName(group);
        return result;
    }

    @Override
    public String toString() {
        return "PredictGroupDTO{" +
            "openid='" + openid + '\'' +
            ", group='" + group + '\'' +
            ", rank=" + rank +
            ", countryId=" + countryId +
            '}';
    }


}
